package com.ruoyi.web.controller.lucky;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lucky.domain.TRecharge;
import com.ruoyi.lucky.service.ITRechargeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充值管理Controller
 * 
 * @author ruoyi
 * @date 2020-11-12
 */
@Controller
@RequestMapping("/lucky/recharge")
public class TRechargeController extends BaseController
{
    private String prefix = "lucky/recharge";

    @Autowired
    private ITRechargeService tRechargeService;

    @RequiresPermissions("lucky:recharge:view")
    @GetMapping()
    public String recharge()
    {
        return prefix + "/recharge";
    }

    /**
     * 查询充值管理列表
     */
    @RequiresPermissions("lucky:recharge:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TRecharge tRecharge)
    {
        startPage();
        List<TRecharge> list = tRechargeService.selectTRechargeList(tRecharge);
        return getDataTable(list);
    }

    /**
     * 导出充值管理列表
     */
    @RequiresPermissions("lucky:recharge:export")
    @Log(title = "充值管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRecharge tRecharge)
    {
        List<TRecharge> list = tRechargeService.selectTRechargeList(tRecharge);
        ExcelUtil<TRecharge> util = new ExcelUtil<TRecharge>(TRecharge.class);
        return util.exportExcel(list, "recharge");
    }

    /**
     * 新增充值管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存充值管理
     */
    @RequiresPermissions("lucky:recharge:add")
    @Log(title = "充值管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TRecharge tRecharge)
    {
        return toAjax(tRechargeService.insertTRecharge(tRecharge));
    }

    /**
     * 修改充值管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TRecharge tRecharge = tRechargeService.selectTRechargeById(id);
        mmap.put("tRecharge", tRecharge);
        return prefix + "/edit";
    }

    /**
     * 修改保存充值管理
     */
    @RequiresPermissions("lucky:recharge:edit")
    @Log(title = "充值管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TRecharge tRecharge)
    {
        return toAjax(tRechargeService.updateTRecharge(tRecharge));
    }

    /**
     * 删除充值管理
     */
    @RequiresPermissions("lucky:recharge:remove")
    @Log(title = "充值管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tRechargeService.deleteTRechargeByIds(ids));
    }
}
